import { StationNetwork } from "GameLoop/Path/StationNetwork";
import { generateUniqueId } from "utils/utils"

export class TaskHelper
{
    public static getTaskPathCost(room:string,workroom?:string)
    {
        if(workroom)
        {
            const route = StationNetwork.getInstance.findRoute( room,workroom)
            if(route)
            {
                return route.value.route.length*50;
            }
            else
            {
                const v = Game.map.getRoomLinearDistance(room,workroom) * 50+1;
                return v?v:50;
            }
        }
        else
        {
            return 49;
        }
    }
    /**
     * 
     * @param role 角色名
     * @param priority 优先级
     * @param task_ttl 任务生命周期
     * @returns 
     */
    public static getSpawnTask(owner:string,bodyconfig:IBodyConfig|undefined,priority:number,task_ttl:number=1500)
    {
        const taskdata:ISpawnData={
            OwerID:owner,
            // priority:priority,
            spawn_info:bodyconfig?[{bodyconfig:bodyconfig,count:1}]:[]
        }
        const task:ITask<ISpawnData>={
            id:generateUniqueId(),
            type:"spawn",
            priority:priority,
            // shard:0,
            ttl:task_ttl,
            data:taskdata
        }
        return task
    }
    
    public static pushSpawnInfo(task:ITask<ISpawnData>,bodyconfig:IBodyConfig,num:number=1)
    {
        task.data.spawn_info.push({bodyconfig:bodyconfig,count:num});
        return task;
    }
     /**
     * 
     * @param role 角色名
     * @param priority 优先级
     * @param task_ttl 任务生命周期
     * @returns 
     */
      public static getSpawnGroupTask(owner:string,configs:[IBodyConfig,number][],priority:number,task_ttl:number=1500)
      {
        const spawninfos:ISpawnInfo[] = [];
        for(const e of configs)
        {
            spawninfos.push( {
                bodyconfig:e[0],
                count:e[1] 
            })
        }
    
          const taskdata:ISpawnData={
            OwerID:owner,
            // priority:priority,
            spawn_info:spawninfos
        }
          const task:ITask<ISpawnData>={
            id:generateUniqueId(),
              type:"spawn",
              priority:priority,
            //   shard:0,
              ttl:task_ttl,
              data:taskdata
          }
          return task
      }
}